package com.wdl.sm.webui.security;

import org.springframework.data.annotation.Id;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class SUser {
    public static final String ROLE_ADMIN = "ADMIN";
    public static final String ROLE_VIEW = "VIEW";

    private static final BCryptPasswordEncoder bc = new BCryptPasswordEncoder(4);

    @Id
    private String id;

    // id
    private String name;

    // user name
    private String desc;

    private String tel;

    // used to get password back
    private String email;

    private String role;
    private String password;

    public SUser() {}

    public SUser(String name, String role, String password) {
        this.name = name;
        this.role = role;
        this.password = bc.encode(password);
        this.desc = name;
        this.tel = "";
        this.email = name + "@wdl.com";
    }

    public SUser(String name, String desc, String tel, String email, String role, String password) {
        this.name = name;
        this.desc = desc;
        this.tel = tel;
        this.role = role;
        this.password = bc.encode(password);
        this.email = email;
    }

    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    @Override
    public String toString() {
        return String.format("User[id=%s, name='%s', email='%s', role='%s', password='%s']", id, name, email, role, password);
    }
}
